<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1">
	<title>停车场管理系统</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/auth.css">
</head>

<body>
	<div class="lowin lowin-blue">
		<div class="lowin-brand">
			<img src="${pageContext.request.contextPath }/img/kodinger.jpg" alt="logo">
		</div>
		<div class="lowin-wrapper">
			<div class="lowin-box lowin-login">
				<div class="lowin-box-inner">
					<form id="loginform" action="" method="post">
						<p>欢迎使用停车场管理系统</p>
						<div class="lowin-group">
							<label>账号: <a href="#" class="login-back-link">返回登录?</a></label>
							<input type="text" name="username" class="lowin-input">
						</div>
						<div class="lowin-group password-group">
							<label>密码: <a href="#" class="forgot-link">忘记密码?</a></label>
							<input type="password" name="password" class="lowin-input">
						</div>
						<button id="loginbutton" class="lowin-btn login-btn">
							Sign In
						</button>

						<div class="text-foot">
							记住账号<input type="checkbox" name="remember" value="true"/>
							还没有账号? <a href="" class="register-link">注册</a>
						</div>
					</form>
				</div>
			</div>

			<div class="lowin-box lowin-register">
				<div class="lowin-box-inner" id="lowin-box-inner">
					<form id="registerform" method="post">
						<p>注册一个账号</p>
						<div class="lowin-group">
							<label>账号:</label>
							<input type="text" name="registerusername" class="lowin-input">
							<span id="exist"></span>
						</div>
						<div class="lowin-group">
							<label>密码:</label>
							<input type="password" name="registerpassword" autocomplete="current-password" class="lowin-input">
							<span></span>
						</div>
						<button id="registerbutton" class="lowin-btn" type="submit">
							Register
						</button>

						<div class="text-foot">
							账号完成创建? <a href="" class="login-link">登录</a>
						</div>
					</form>
				</div>
			</div>
		</div>
		<footer class="lowin-footer">
			
		</footer>
	</div>
	
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/auth.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.validate.js"></script>
	<script>
		Auth.init({
			login_url: '/Parking/user/login',
			forgot_url: '#forgot'
		});
		
		$(function(){
			
			
/* 			$("input[name=registerusername]").blur(function() {
				$.ajax({
					url : "/Parking/user/check",
					type : "post",
					data : {
						name : $(this).val().trim()
					},
					success : function(result) {
						// 成功之后执行的函数
						// result 代表response返回的结果
						$("#exist").text(result)
					}
				});
			});
		
			$("input[name=registerusername]").focus(function(){
				$("#exist").text("")
			}); */ 
			
   			$("#registerbutton").click(function(){
				$.ajax({
					url:"${pageContext.request.contextPath }/user/register",
					type:"post",
					data:$("#registerform").serialize(),
					success:function(result){
						if(result == true){
							alert("注册成功");
						}else{
							alert("注册失败");
						}
					}
				});
			}); 
			
  			$("#loginform").validate({
				rules:{
					username:{
						required:true
					}
				},
				messages:{
					username:{
						required:"请先输入账户进行登录"
					}
				}
			}); 
  			
  			$("#registerform").validate({
				rules:{
					registerusername:{
						required:true,
						remote:{
							url:"/Parking/user/check",
							type:"post"
						}
					},
					registerpassword:{
						required:true
					}
				},
				messages:{
					registerusername:{
						required:"用户名不能为空",
						remote:"用户名已存在"
					},
					registerpassword:{
						required:"密码不能为空",
					}
				}
			}); 
		}); 
	</script>
</body>
</html>